//
//  MainTabBar.swift
//  个人微博
//
//  Created by 一介布衣 on 16/2/13.
//  Copyright © 2016年 HUAMANLOU. All rights reserved.
//

import UIKit

class MainTabBar: UITabBar {

    // 布局子视图的方法
    override func layoutSubviews() {
        super.layoutSubviews()
        
        // 确定tabBarButton的大小
        let w = self.bounds.width / 5.0
        let h = self.bounds.height
        let rect = CGRect(x: 0, y: 0, width: w, height: h)
        
        // 定义一个索引，来进行递增
        var index:CGFloat = 0
        
        // 遍历子视图
        for subview in subviews {
            if subview.isKindOfClass(NSClassFromString("UITabBarButton")!) {
                // 修改frame
                subview.frame = CGRectOffset(rect, w * index, 0)
                
                index += (index == 1 ? 2:1)
            }
            
            // 设置➕按钮的位置
            plusBtn.frame = CGRectOffset(rect, 2*w, 0)
        }
        
    }
    
    /// 懒加载➕按钮
    lazy var plusBtn: UIButton = {
        
        let btn = UIButton()
        // 设置图片
        btn.setImage(UIImage(named: "tabbar_compose_icon_add"), forState: .Normal)
        btn.setImage(UIImage(named: "tabbar_compose_icon_add_highlighted"), forState: .Highlighted)
        
        // 设置背景图片
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button_highlighted"), forState: .Highlighted)
        btn.setBackgroundImage(UIImage(named: "tabbar_compose_button"), forState: .Normal)
        
        self.addSubview(btn)
        
        return btn
    }()


}
